<?php
class IndexAction extends CommonAction {
	
	// 框架首页
	public function index() {
		if (isset ( $_SESSION [C ( 'USER_AUTH_KEY' )] )) {
			//显示菜单项
			$menu = array ();
			
			//读取数据库模块列表生成菜单项
			$node = M ( "Node" );
			$id = $node->getField ( "id" );
			$where ['level'] = 2;
			$where ['status'] = 1;
			$where ['pid'] = $id;
			$list = $node->where ( $where )->field ( 'id,name,group_id,title' )->order ( 'sort asc' )->select ();
			$accessList = $_SESSION ['_ACCESS_LIST'];
			foreach ( $list as $key => $module ) {
				if (isset ( $accessList [strtoupper ( APP_NAME )] [strtoupper ( $module ['name'] )] ) || $_SESSION ['administrator']) {
					//设置模块访问权限
					$module ['access'] = 1;
					$menu[$module['group_id']] [$key] =$module;
				}
			}
			
			if (! empty ( $_GET ['tag'] )) {
				$this->assign ( 'menuTag', $_GET ['tag'] );
			}
			//dump($menu);
			$groups=M("Group")->where(array('status'=>"1"))->order("sort desc,id desc")->select();
			if($_SESSION['administrator']||$_SESSION['role_id']>2){
                $this->assign("groups",$groups);
            }else{
                $groups1[0]=$groups[0];
                $this->assign("groups",$groups1);
            }
			$this->assign ( 'menu', $menu );

//公告部分


            $map = $this->_search ();
            $map['InfoStatus']='1';//状态为1表示启用
            if (method_exists ( $this, '_filter' )) {
                $this->_filter ( $map );
            }
            $name="Gonggao";
            $model = D ($name);
            if (! empty ( $model )) {
                $this->_list ( $model, $map );
            }

            $Gonggao = D("Gonggao");
            $rs=$Gonggao->where('InfoStatus=1')->field('create_time')->order('create_time desc')->find();
            Log::write('rs | ' . dump($rs,false), Log::DEBUG);
            $MaxDate=$rs['create_time'];
            $where="create_time='$MaxDate' and InfoStatus='1' ";
            $LastGonggao=$Gonggao->where($where)->select();
            Log::write('LastGonggao | ' . dump($LastGonggao,false), Log::DEBUG);
            $this->assign ( 'LastGonggao', $LastGonggao );
//
        }
        C ( 'SHOW_RUN_TIME', false ); // 运行时间显示
        C ( 'SHOW_PAGE_TRACE', false );
        $city_list=C(CITY);
        $this->assign("city_list",$city_list);
        $this->display ();
	}

}
?>